<template>
	<view class="paper__container">
		<!-- 菜单 -->
		<leftPopup v-model:show="show" @clearRead="clearRead" @adddriend="adddriend"/>
		<!-- 小纸条列表 -->
		<paperList v-for="(item,index) in list" :key="index" :item="item"/>
		<!-- 下拉加载 -->
		<loadMore :loadingText="loadingText" v-show="list.length>9"/>
	</view>
</template>

<script setup>
	import paperList from '../../component/paper/paper-list.vue';
	import loadMore from '../../component/common/load-more.vue';
	import leftPopup from '../../component/paper/paper-left-popup.vue'
	import {reactive,ref} from 'vue';
	import user from '../../common/user.js'
	import {onPullDownRefresh,onReachBottom,onNavigationBarButtonTap} from '@dcloudio/uni-app'
	const list = ref([
		{
			userpic:"../../static/new.jpg",
			username:"JIA一勺",
			time:"20:30",
			data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
			noreadnum:212,
		},
		{
			userpic:"../../static/new.jpg",
			username:"JIA一勺",
			time:"20:30",
			data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
			noreadnum:212,
		},{
			userpic:"../../static/new.jpg",
			username:"JIA一勺",
			time:"20:30",
			data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
			noreadnum:2,
		},{
			userpic:"../../static/new.jpg",
			username:"JIA一勺",
			time:"20:30",
			data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
			noreadnum:0,
		},{
			userpic:"../../static/new.jpg",
			username:"JIA一勺",
			time:"20:30",
			data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
			noreadnum:212,
		}
		
	]);
	
	const loadingText = ref("上拉加载更多")

	const show = ref(false)

	// 下拉刷新
	onPullDownRefresh(()=>{
		setTimeout(()=>{
			list.value= [
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:2,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:0,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			{
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:212,
			},
			];
			uni.stopPullDownRefresh();
		},2000)
	})
	
	// 上拉加载
	onReachBottom(()=>{
		if(loadingText.value!="上拉加载更多")return;
			loadingText.value = "加载中...";
		setTimeout(()=>{
			list.value.push({
				userpic:"../../static/new.jpg",
				username:"JIA一勺",
				time:"20:30",
				data:"123测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试",
				noreadnum:Math.random()*30,
			})
			loadingText.value="上拉加载更多";
		},1000)
	})
	
	// 添加好友
	function adddriend(){
		show.value = false;
		console.log("添加好友")
	}
	
	// 清除已读
	function clearRead(){
		console.log("清除已读")
	}
	
	onNavigationBarButtonTap((e)=>{
		
		switch(e.index){
			case 0:
				show.value=false;
				user.navigate({
					url:"/pages/user-list/user-list"
				})
				break;
			case 1:
				show.value = !show.value;
				break;
		}
	})
	
	
	
	
	
</script>

<style lang="scss" scoped>
.paper__container {
	min-height: 100%;
	padding: 20upx;
	box-sizing: border-box;

}

</style>
